﻿#ifndef MessageDispatcher_h__
#define MessageDispatcher_h__

/********************************************************************
	创建于:		2011/04/05
	创建于:		5:4:2011   13:38
	基本文件:	MessageDispatcher
	文件扩展:	h
	作者:		王凯
	
	目的:		消息传递类。用来管理Telegram消息。该类是一个单价类。
*********************************************************************/

#include <set>
#include <string>
#include "Messaging/Telegram.h"

class BaseGameEntity;

//让代码简单易读
const double SEND_MSG_IMMEDIATELY = 0.0f;
const int    NO_ADDITIONAL_INFO   = 0;
const int    SENDER_ID_IRRELEVANT = -1;

#define Dispatch MessageDispatcher::Instance()

class MessageDispatcher
{
private:

	std::set<Telegram> PriorityQ;

	void Discharge(BaseGameEntity* pReceiver, const Telegram& msg);

	MessageDispatcher(){};

	//拷贝构造和赋值运算
	MessageDispatcher(const MessageDispatcher&){};
	MessageDispatcher& operator=(const MessageDispatcher&){};

public:

	static MessageDispatcher* Instance();

	//传递消息
	void DispatchMsg(double delay,
		int sender,
		int receiver,
		int msg,
		void* extro = NULL);

	//传递延迟消息
	void DispatchDelayedMessages();
};


#endif // MessageDispatcher_h__